<template>
  <div class="tab-bar-item" @click="itemClick">
    <div class="icon" v-if="!isActive"><slot name="item-icon"></slot></div>
    <div class="iconActive" v-else><slot name="item-icon-active"></slot></div>
    <div :style="styleActive" ><slot name="item-text"></slot></div>
  </div>
</template>

<script>
// import { defineComponent } from '@vue/composition-api'

export default({
  name:'TabBarItem',
  props:{
    path:String,
    activeColor:{
      type:String,
      default:'red'
    }
  },
  data(){
    return {

    }
  },
  computed:{
    isActive(){
      return this.$route.path.indexOf(this.path)!==-1;
    },
    styleActive(){
      return this.isActive?{color:this.activeColor}:{};
    }
  },
  methods:{
    itemClick(){
     this.$router.replace(this.path)
    }
  }
})
</script>

<style>
.tab-bar-item{
  flex:1;
  text-align: center;
  height: 49px;
  font-size: .875rem;
}
.tab-bar-item img{
  width: 1.5rem;
  height: 1.5rem;
  margin-top: .25rem;
  vertical-align: middle;
}
.tab-bar-item .active{
  color: red;
}
</style>
